/*                          UX-Framework                               
 *                                                                 
 *  iZE Co.,Ltd. Copyright 2009 All rights reserved.          
 *  This file is distributed under the terms of the GNU Lesser 
 *  General Public License, described in file LICENSE.                                     
 */
package jp.ize.ux.components.themes.basic;

// {{{ imports
import jp.ize.ux.components.UXSlider;
import jp.ize.ux.components.UXResource;
import jp.ize.ux.components.UXComponentResource;
import jp.ize.ux.geom.UXSize;
import flash.display.MovieClip;
import flash.display.GradientType;
import flash.geom.Matrix;
// }}}
// {{{ class UXSliderResource
/** 
 * UXSliderResource クラス<br>
 * コンポーネントの描画に利用されるリソース情報です。<br>
 *
 * @author		iZE Co., Ltd.<br>
 * @version		$Id: UXSlider.hx 20 2009-02-04 08:23:19Z yimai.v $<br>
 */
class UXSliderResource extends UXComponentResource
{
	// {{{ properties

	public var s:UXSliderState;
	public var trac:UXComponentResource;
	public var thumb:UXComponentResource;

	// }}}
	// {{{ public function new( s:UXSliderState, dir:UXSliderDirection, ?res:Dynamic ) : Void
	/**
	* コンストラクタ
	*/
	public function new( s:UXSliderState, dir:UXSliderDirection, ?res:Dynamic ) : Void
	{
		super(res,false);
		this.s = s;
		this.trac  = getTrac(s,dir);
		this.thumb = getThumb(s,dir);
	}

	// }}}
	// {{{ public function getTrac( s:UXSliderState, dir:UXSliderDirection ) : UXComponentResource

	public function getTrac( s:UXSliderState, dir:UXSliderDirection ) : UXComponentResource
	{
		var mc = new MovieClip();
		var me = this;
		// {{{ normal
		var normal:MovieClip->Void = function( mc:MovieClip ) {
			var s = me.s;
			var g = mc.graphics;
			g.clear();
			if ( dir==HORIZONTAL ) {
				g.lineStyle( 1.0, 0x999999 );
				g.beginFill( 0xCCCCCC );
				g.drawRect( 0, s.size.height/2-2, s.size.width, 4 );
				g.endFill();
				g.lineStyle( 1.0, 0x999999, 0.0 );
				g.beginFill( 0xAAAAAA, 0.0 );
				g.drawRect( 0, 0, s.size.width, s.size.height );
				g.endFill();
			} else {
				g.lineStyle( 1.0, 0x999999 );
				g.beginFill( 0xCCCCCC );
				g.drawRect( s.size.width/2-2, 0, 4, s.size.height );
				g.endFill();
				g.lineStyle( 1.0, 0x999999, 0.0 );
				g.beginFill( 0xAAAAAA, 0.0 );
				g.drawRect( 0, 0, s.size.width, s.size.height );
				g.endFill();
			}
		}
		// }}}
		// {{{ disabled
		var disabled:MovieClip->Void = function( mc:MovieClip ) {
			var s = me.s;
			var g = mc.graphics;
			g.clear();
			g.lineStyle( 1.0, 0xAAAAAA );
			//g.beginGradientFill( GradientType.LINEAR, colors, alphas, ratios, matrix );
			g.beginFill( 0xCCCCCC );
			if ( dir==HORIZONTAL ) {
				g.drawRect( 0, s.size.height/2-2, s.size.width, 4 );
			} else {
				g.drawRect( s.size.width/2-2, 0, 4, s.size.height );
			}
			g.endFill();
		}
		// }}}
		var comres = new UXComponentResource(mc);
		comres.setNormal(   Draw(normal) );
		comres.setDisabled( Draw(disabled) );
		comres.normal();
		//comres.disabled();
		return comres;
	}

	// }}}
	// {{{ public function getThumb( s:UXSliderState, dir:UXSliderDirection ) : UXComponentResource

	public function getThumb( s:UXSliderState, dir:UXSliderDirection ) : UXComponentResource
	{
		var mc = new MovieClip();
		var me = this;
		// {{{ normal
		var normal:MovieClip->Void = function( mc:MovieClip ) {
			var s = me.s;
			var ty = 3;
			var colors:Array<UInt> = [ 0x99FF99, 0x00FF00 ];
			var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
			var ratios:Array<UInt> = [ 0, 255 ];
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox( s.size.width, s.size.height-ty*2, Math.PI/2, 0, ty );

			var g = mc.graphics;
			g.clear();
			var d = 2;
			if ( dir==HORIZONTAL ) {
				var val = 10;
				g.lineStyle( 1.0, 0x888888 );
				g.beginFill( 0x888888 );
				g.drawRect( 0, 0, val, s.size.height );
				g.endFill();
				g.lineStyle( 1.0, 0xFFFFFF );
				g.moveTo( d,     s.size.height/2-3 ); 
				g.lineTo( val-d, s.size.height/2-3 ); 
				g.moveTo( d,     s.size.height/2   ); 
				g.lineTo( val-d, s.size.height/2   ); 
				g.moveTo( d,     s.size.height/2+3 ); 
				g.lineTo( val-d, s.size.height/2+3 ); 
			} else {
				var val = 10;
				g.lineStyle( 1.0, 0x888888 );
				g.beginFill( 0x888888 );
				g.drawRect( 0, 0, s.size.width, val );
				g.endFill();
				g.lineStyle( 1.0, 0xFFFFFF );
				g.moveTo( d,              val/2-2 ); 
				g.lineTo( s.size.width-d, val/2-2 ); 
				g.moveTo( d,              val/2+2 ); 
				g.lineTo( s.size.width-d, val/2+2 ); 
			}
		}
		// }}}
		// {{{ disabled
		var disabled:MovieClip->Void = function( mc:MovieClip ) {
			var s = me.s;
			var ty = 3;
			var colors:Array<UInt> = [ 0x99FF99, 0x00FF00 ];
			var alphas:Array<Dynamic> = [ 1.0, 1.0 ];
			var ratios:Array<UInt> = [ 0, 255 ];
			var matrix:Matrix = new Matrix();
			matrix.createGradientBox( s.size.width, s.size.height-ty*2, Math.PI/2, 0, ty );

			var g = mc.graphics;
			g.clear();
			var ty = 4;
			if ( dir==HORIZONTAL ) {
				var val = 10;
				g.lineStyle( 1.0, 0xCCCCCC );
				g.beginFill( 0xEEEEEE );
				g.drawRect( 0, 0, val, s.size.height );
				g.endFill();
			} else {
				var val = 10;
				g.lineStyle( 1.0, 0xCCCCCC );
				g.beginFill( 0xEEEEEE );
				g.drawRect( 0, 0, s.size.width, val );
				g.endFill();
			}
		}
		// }}}
		var comres = new UXComponentResource(mc);
		comres.setNormal(   Draw(normal) );
		comres.setDisabled( Draw(disabled) );
		comres.normal();
		//comres.disabled();
		return comres;
	}

	// }}}
}
// }}}
